package unclassified.medium;

public class WateringPlants_5201 {

    public int wateringPlants(int[] plants, int capacity) {
        int l = 0, curCapacity = capacity;
        int ans = 0;
        while (l < plants.length) {
            if(plants[l] <= curCapacity) {
                ans++;
                curCapacity = curCapacity -  plants[l];
            } else if (plants[l] > curCapacity) {
                ans += l;
                curCapacity = capacity;
                ans += l + 1;
                curCapacity = curCapacity - plants[l];
            }
            l++;
        }
        return ans;
    }

    public static void main(String[] args) {
        WateringPlants_5201 wp = new WateringPlants_5201();
        System.out.println(wp.wateringPlants(new int[]{3, 2, 4 , 2, 1}, 6));
    }

}
